package com.net.tomcat5;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 支持post请求
 *
 * @author jiangbang
 * @date 2016/8/24
 */
public class Server3 {
    private ServerSocket server;


    public static void main(String[] args) {
        Server3 server = new Server3();
        server.start();
    }

    //启动方法
    public void start(){
        try {
             server = new ServerSocket(8888);
            this.receive();
        } catch (IOException e) {
        }
    }
    //结束方法
    public void stop(){

    }

    //接受客户端
    private void receive(){
        try {
            Socket client = server.accept();

            Request request = new Request(client.getInputStream());

            //接受客户端请求信息
            byte[] data = new byte[20480];
           int len = client.getInputStream().read(data);
            String requestInfo = new String(data,0,len).trim();
            System.out.println(requestInfo);

            //响应到前端
            StringBuilder content = new StringBuilder();
            content.append("<html><head><title>第一个表单</title></head><body>1234</body></html>");
            Response response = new Response(client.getOutputStream());
            response.print(content.toString());
            response.pushToClient(200);

        } catch (IOException e) {

        }
    }
}
